我刚刚为MacOS X安装了Python 3.6.1 当我尝试运行控制台(或使用Python3运行任何命令)时,抛出此错误: AttributeError:模块“枚举”没有属性“ IntFlag” $ /库/框架/Python.framework/版本/3.6/bin/python3 无法导入站点模块 追溯(最近一次通话):中的文件“ /usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py”,行544 主要() 主文件530行中的文件“ /usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py” known_paths = addusersitepackages(known_paths) addusersitepackages中的文件“ /usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py”,第282行 user_site = getusersitepackages() getusersitepackages中的文件“ /usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py”,第258行 user_base = getuserbase()#这也将设置USER_BASE getuserbase中的文件“ /usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py”,第248行 USER_BASE = get_config_var('用户库') get_config_var中的第601行的文件“ /usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/sysconfig.py” 返回get_config_vars()。get(name) get_config_vars中的文件“ /usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/sysconfig.py”,第580行 导入_osx_support <模块>中第4行的文件“ /usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/_osx_support.py” 汇入 中的文件“ /usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/re.py”,第142行 RegexFlag(enum.IntFlag)类: AttributeError:模块“枚举”没有属性“ IntFlag” IntFlag类存在于enum.py中。那么,为什么会抛出AttributeError?
2021-01-02 08:10:19
这是因为您的枚举不是标准库枚举模块。您可能已经安装了enum34软件包。 检查是否是这种情况的一种方法是检查属性enum。__file__ 导入枚举 打印(枚举__file__) #标准库位置应类似于 #/usr/local/lib/python3.6/enum.py 从python 3.6开始,enum34库不再与标准库兼容。该库也是不必要的,因此您可以简单地将其卸载。 pip卸载-y enum34 如果您需要代码同时在<= 3.4和> 3.4的python版本上运行,则可以尝试将enum-compat作为要求。它只为旧版本的python安装enum34,而没有标准库enum。 | 不知道您是否仍然有此问题。我有一个类似的问题,只需取消PYTHONPATH就可以解决 $未设置PYTHONPATH | 对我来说,此错误是在安装gcloud组件app-engine-python以便集成到pycharm后发生的。即使pycharm现在不上传到app-engine,卸载模块也有帮助。 | 如果有人在PyCharm中运行Google App Engine Python 3.7标准环境项目时由于遇到此错误而来这里,那么您所需要做的就是 确保要运行的配置适用于Flask,而不适用于Google App Engine配置。 然后在偏好设置>>语言和框架>> Google App Engine下禁用Google App Engine支持 原因是根据此链接 总体目标是您的应用程序应具有完全可移植性,并可以在任何标准Python环境中运行。您编写的是标准Python应用程序,而不是App Engine Python应用程序。作为此转变的一部分,您不再需要为应用程序的核心功能使用专有的App Engine API和服务。目前,Python 3.7运行时中不提供App Engine API。 我猜想当我们在PyCharm中将python 3.7项目创建为Google应用程序引擎项目时,它仍会尝试以与python2.7应用程序相同的方式进行操作 | 免责声明:请@ juanpa.arrivillaga,如果您看到此答案,请随时写自己的答案,我将删除此帖子。 @ juanpa.arrivillaga上面已经提到: 您的工作目录中是否有文件名enum.py? 这就是我遇到的问题。当时我还不知道python上的enum模块,并已将测试文件命名为enum.py。 由于文件名是模块名,因此存在冲突。有关模块的更多信息,请参见:https://docs.python.org/2/tutorial/modules.html | 在pycharm首选项中禁用“ Google App Engine支持”对我来说解决了这个问题。 | 安装enum34的1.1.8版本对我有用。 我可以通过向pyproject.toml添加enum34 =“ == 1.1.8”来解决此问题。 显然enum34在v1.1.8中具有避免此错误的功能,但是 这在v1.1.9 +中已退回。不过,这只是一种解决方法。的 更好的解决方案是使程序包使用环境标记,以便 除非需要,否则根本不需要安装enum34。 资料来源:https://github.com/python-poetry/poetry/issues/1122 | HåkenLid的回答帮助解决了我的问题(谢谢!),在我的情况下,在运行于Docker容器中的Flask的Python3.7中(FROM tiangolo / uwsgi-nginx-flask:python3.7-alpine3.7)。 就我而言,enum34是由另一个库安装的(pip install smartsheet-python-sdk)。 对于那些遇到类似的Docker容器问题的人,这是我的最终Dockerfile(跳至相关行): 来自tiangolo / uwsgi-nginx-flask:python3.7-alpine3.7 ... RUN pip install -r requirements.txt RUN pip卸载-y enum34 ... | 如果必须同时为python2和python3保留PYTHONPATH,则可以编写别名语句以在bash_profile中设置适当的PYTHONPATH: 在〜/ .bash_profile中,对PYTHONPATH2和PYTHONPATH3变量进行硬编码,并在其末尾添加以下别名: 别名python ='export PYTHONPATH = $ {PYTHONPATH2}; python' 别名python3 ='export PYTHONPATH = $ {PYTHONPATH3}; python3' 我的python(指python2)是因为我更频繁地使用python2。 | 每当我遇到这个问题时: AttributeError:模块“枚举”没有属性“ IntFlag” 只需首先运行命令: 未设定PYTHONPATH 然后运行我想要的命令,然后就成功了。 | 我通过使用pip install--ignore-installed enum34做到了 安装所需的库后,请在构建过程中查找警告。 我收到了这样的错误:由于未安装软件包'wheel',因此将来使用legacy setup.py安装会出错:pyejabberd 0.2.11的要求enum34 == 1.1.2,但是您将拥有不兼容的enum34 1.1.10 。 要解决此问题,请运行以下命令:pip Frozen | grep枚举34。这将为您提供已安装的enum34的版本。现在通过pip卸载enum34进行卸载,并重新安装所需的版本,如pip install“ enum34 == 1.1.20” | 如果在PyCharm中运行测试时遇到此问题,请确保未选中第二个框配置。 | 我的计算机上安装了Python 2和Python 3。出于某些奇怪的原因,当调用re模块时,我在Python 3的sys.path中也有一个指向Python2的sitepackage库目录的路径。如果我运行Python 3并导入enum和print(enum .__ file__),则系统不会显示该Python 2站点包路径。因此,一个非常粗糙和肮脏的技巧是直接修改导入枚举的模块(遵循回溯路径),并在导入枚举之前插入以下代码: 导入系统 对于我,枚举(sys.path)中的p: 如果p.lower()中的“ python27”或p.lower()中的“ python2.7”:sys.path.pop(i) 导入枚举 那解决了我的问题。 | 即使我在运行python -m grpc_tools.protoc --version时遇到了这个问题 必须设置PYTHONPATH直到站点包并关闭所有命令提示符窗口,然后它才能工作。希望它对gRPC用户有所帮助。 | 我在使用python3.8和tensorflow 2.2.0的虚拟环境内核中的jupyterlab的ubuntu20.04中遇到了这个问题。错误消息原为 追溯(最近一次通话): _run_module_as_main中的文件“ /usr/lib/python2.7/runpy.py”,第174行 “ __main __”,fname,loader,pkg_name) _run_code中的文件“ /usr/lib/python2.7/runpy.py”,第72行 run_globals中的exec代码 <模块>中第15行的文件“ /home/hu-mka/.local/lib/python2.7/site-packages/ipykernel_launcher.py” 从ipykernel导入kernelapp作为应用 <模块>中第2行的文件“ /home/hu-mka/.local/lib/python2.7/site-packages/ipykernel/__init__.py” 来自.connect import * <模块>中第13行的文件“ /home/hu-mka/.local/lib/python2.7/site-packages/ipykernel/connect.py” 从IPython.core.profiledir导入ProfileDir 中的文件“ /home/hu-mka/.local/lib/python2.7/site-packages/IPython/__init__.py”,第48行 从.core.application导入应用程序 <模块>中第23行的文件“ /home/hu-mka/.local/lib/python2.7/site-packages/IPython/core/application.py” 从traitlets.config.application导入应用程序,catch_config_error 在 中的第1行,文件“ /home/hu-mka/.local/lib/python2.7/site-packages/traitlets/__init__.py” 从.traitlets导入* 在 中的文件“ /home/hu-mka/.local/lib/python2.7/site-packages/traitlets/traitlets.py”,第49行 导入枚举 ImportError:没有名为枚举的模块 问题是在/ usr / bin / python中的符号链接中指向python2。解: 光盘/ usr / bin / 须藤ln -sf python3 python 希望Python 2的使用将很快完全消失。 | 从HuggingFace安装变压器库时遇到此问题。这是由于在我的环境中安装了enum34软件包,该软件包覆盖了Python中的内置enum。安装此软件包的原因可能是为了实现向前兼容性,而Python 3.6+不再需要此软件包。所以解决方案很简单, pip卸载-y enum34 | 不幸的是,这些建议都没有帮助我,但是在进一步搜索之后 点安装aenum 为我解决了 | 如果有人尝试从virtualenv运行Jupyter内核时遇到此问题,只需将正确的PYTHONPATH添加到virtualenv内核的kernel.json中(例如Python 3): { “ argv”:[ “ /usr/local/Cellar/python/3.6.5/bin/python3.6”, “ -m”, “ ipykernel_launcher”, “-F”, “ {connection_file}” ], “ display_name”:“ Python 3(TensorFlow)”, “ language”:“ python”, “ env”:{ “ PYTHONPATH”:“ /Users/dimitrijer/git/mlai/.venv/lib/python3.6:/Users/dimitrijer/git/mlai/.venv/lib/python3.6/lib-dynload:/usr/local/地窖/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6:/Users/dimitrijer/git/mlai/.venv/lib/python3.6/site-packages” } } | 你的答案 StackExchange.ifUsing(“ editor”,function(){ StackExchange.using(“ externalEditor”,function(){ StackExchange.using(“ snippets”,function(){ StackExchange.snippets.init(); }); }); },“代码段”); StackExchange.ready(function(){ var channelOptions = { 标签:“” .split(“”), id:“ 1” }; initTagRenderer(“”。split(“”),“” .split(“”),channelOptions); StackExchange.using(“ externalEditor”,function(){ //如果启用了摘要,则必须在摘要后触发编辑器 如果(StackExchange.settings.snippets.snippetsEnabled){ StackExchange.using(“ snippets”,function(){ createEditor(); }); } 其他{ createEditor(); } }); 函数createEditor(){ StackExchange.prepareEditor({ useStacksEditor:否, heartbeatType:“答案”, autoActivateHeartbeat:否, convertImagesToLinks:是, noModals:是的, showLowRepImageUploadWarning:是的, 声望:ToPostImages:10, bindNavPrevention:正确, 后缀:“”, imageUploader:{ brandingHtml:“采用\ u003ca href = \“ https://imgur.com/ \” \ u003e \ u003csvg class = \“ svg-icon \” width = \“ 50 \” height = \“ 18 \” viewBox = \“ 0 0 50 18 \” fill = \“ none \” xmlns = \“ http://www.w3.org/2000/svg \” \ u003e \ u003cpath d = \“ M46.1709 9.17788C46.1709 8.26454 46.2665 7.94324 47.1084 7.58816C47.4091 7.46349 47.7169 7.36433 48.0099 7.26993C48.9099 6.97997 49.672 6.73443 49.672 5.93063C49.672 5.22043 48.98324.61182 48.1414 4.61182C47.4335 4.61182 46.7256 4.91628 46.0943 5.50789C45.7307 4.9328 45.2525 4.66231 44.6595 4.66231C43.6264 4.66231 43.1481 5.28821 43.1481 6.59048V11.9512C43.1481 13.2535 43.6264 13.8962 44.6595 13.8962C45.6924 13.8962 / \ u003e \ u003cpath d = \“ M32.492 10.1419C32.492 12.6954 34.1182 14.0484 37.0451 14.0484C39.9723 14.0484 41.5985 12.6954 41.5985 10.1419V6.59049C41.5985 5.28821 41.1394 4.66232 40.1061 4.66232C39.0732 4.66232 38.5948 5.28821 .5948 10.8521 38.2696 11.5455 37.0451 11.5455C35.8209 11.5455 35.4954 10.8521 35.4954 9.60062V6.59049C35.4954 5.28821 35.0173 4.66232 34.0034 4.66232C32.9703 4.66232 32.492 5.28821 32.492 6.59049V10.1419Z \“ / \ u003e \ d-od-d \“ clip-rule = \” evenodd \“ d = \” M25.6622 17.6335C27.8049 17.6335 29.3739 16.9402 30.2537 15.6379C30.8468 14.7755 30.9615 13.5579 30.9615 11.9512V6.59049C30.9615 5.28821 30.4833 4.66231 29.4502 4.66231C28.9913 4.66231 28.4555 4.9497 8 28.1109 5.50789C27.499 4.86533 26.7335 4.56087 25.7005 4.56087C23.1369 4.56087 21.0134 6.57349 21.0134 9.27932C21.0134 11.9852 23.003 13.913 25.3754 13.913C26.5612 13.913 27.4607 13.4902 28.1109 12.6616C28.1109 12.7229 28.1161 12.7799 28.1212.8934 12.983C28.1301 14.4373 27.2502 15.2321 25.777 15.2321C24.8349 15.2321 24.1352 14.9821 23.5661 14.7787C23.176 14.6393 22.8472 14.5218 22.5437 14.5218C21.7977 14.5218 21.2429 15.0123 21.2429 15.6887C21.2429 16.7375 22.9072 17.6335 25.66224.1633 7。 7.09766 26.1024 7.09766C27.2119 7.09766 28.0918 7.94324 28.0918 9.27932C28.0918 10.6321 27.2311 11.5116 26.1024 11.5116C24.9737 11.5116 24.1317 10.6491 24.1317 9.27932Z \“ / \ u003e \ u003cpath d = \” M16.8045 11.9512C16.8637 13.25 13.8962C19.3298 13.8962 19.8079 13.2535 19.8079 11.9512V8.12928C19.8079 5.82936 18.4879 4.62866 16.4027 4.62866C15.1594 4.62866 14.279 4.98375 13.3609 5.88013C12.653 5.05154 11.6581 4.62866 10.3573 4.62866C9.34336 4.62866 8.57809 4.89931 7.9466 5.5079C7.58314 4.9328 7.10506 4.66232 6.51203 4.66232C5.47873 4.66232 5.00066 5.28821 5.00066 6.59049V11.9512C5.00066 13.2535 5.47873 13.8962 6.51203 13.8962C7.527.9 13.685 0232 7.58817 8.44431 6.91179 9.53458 6.91179C10.5104 6.91179 10.893 7.58817 10.893 8.94108V11.9512C10.893 13.2535 11.3711 13.8962 12.4044 13.8962C13.4375 13.8962 13.9157 13.2535 13.9157 11.9512V8.90741C13.9157 7.58817 6.3579 6.9479 8.45269 V11.9512Z \“ / \ u003e \ u003cpath d = \” M3.31675 6.59049C3.31675 5.28821 2.83866 4.66232 1.82471 4.66232C0.791758 4.66232 0.313354 5.28821 0.313354 6.59049V11.9512C0.313354 13.2535 0.791758 13.8962 3.32471 13.8962C2.81798 13.8962 3.31675 11.9512V6.59049Z \“ / \ u003e \ u003cpath d = \” M1.87209 0.400291C0.843612 0.400291 0 1.1159 0 1.98861C0 2.87869 0.822846 3.57676 1.87209 3.57676C2.90056 3.57676 3.7234 2.87869 3.7234 1.98861C3.7234 1.1159 2.90056 0.400291 1.87209 0.400291Z \“ fill = \”#1BB76E \“ / \ u003e \ u003c / svg \ u003e \ u003c / a \ u003e”, contentPolicyHtml:“根据\ u003ca href = \“ https://stackoverflow.com/help/licensing \” \ u003ecc by-sa \ u003c / a \ u003e \ u003ca href = \“ https://stackoverflow.com获得许可的用户贡献/ legal / content-policy \“ \ u003e(内容策略)\ u003c / a \ u003e”, allowUrls:是 }, onDemand:是的, throwSelector:“。discard-answer” ,立即显示MarkdownHelp:true,enableTables:true,enableSnippets:true }); } }); 感谢您为Stack Overflow提供答案! 请务必回答问题。提供详细信息并分享您的研究! 但是要避免... 寻求帮助,澄清或回答其他答案。 根据意见发表声明;用参考或个人经验来备份它们。 要了解更多信息,请参见我们撰写出色答案的提示。 草稿已保存 草稿丢弃 注册或登录 StackExchange.ready(function(){ StackExchange.helpers.onClickDraftSave('#login-link'); }); 使用Google注册 使用Facebook注册 使用电子邮件和密码注册 提交 以访客身份发布 名称 电子邮件 必需,但从未显示 StackExchange.ready( 函数(){ StackExchange.openid.initPostLogin('。new-post-login','https%3a%2f%2fstackoverflow.com%2fquestions%2f43124775%2fwhy-python-3-6-1-throws-attributeerror-module-enum-has- no-attribute-intflag%23new-answer”,“ question_page”); } ); 以访客身份发布 名称 电子邮件 必需,但从未显示 发表您的答案 丢弃 点击“发布答案”,即表示您同意我们的服务条款,隐私政策和Cookie政策 不是您要找的答案?浏览标记为python python-3.x的其他问题,枚举python-3.6 attributeerror或提出您自己的问题。